const Router = require('koa-router');
const router = new Router();


const Mock = require('mockjs'); //生成模拟数据
const Random = Mock.Random;

router.prefix('/article')

router.get('/page', async (ctx, next) => {
  const param = ctx.query;
  const data = {
    list: [],
    total: 100
  };
  const len =  parseInt(param.size);
  for (let i = 0; i < len; i++) {
    data.list.push({
      id: Random.integer(1, 1000),
      title: Random.csentence(2, 30),
      brief: Random.csentence(2, 200),
      content: Random.csentence(20, 300),
      nodename: Random.csentence(2, 10),
      create_time: parseInt(new Date().getTime() / 1000)
    });
  }
  // await tools.sleep(1000);
  // await tools.sleep(1000);
  ctx.body = tools.stateJson(data);
});

router.get('/:id(\\d+)', (ctx, next) => {
  const param = ctx.query;
  const data = {
    id: param.id,
    title: Random.csentence(2, 30),
    content: Random.csentence(20, 300),
    nodename: Random.csentence(2, 10),
    create_time: parseInt(new Date().getTime() / 1000)
  };
  ctx.body = tools.stateJson(data);
});




module.exports = router;
